package com.wangsd.member.service;

import com.gitee.fastmybatis.core.query.Query;
import com.gitee.fastmybatis.core.query.Sort;
import com.wangsd.member.entity.Member;
import com.wangsd.member.mapper.MemberMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户Service业务层处理
 *
 * @author wsd
 * @date 2021-06-18
 */
@Service
public class MemberService {
    @Autowired
    private MemberMapper memberMapper;

    /**
     * 查询用户
     *
     * @param id 用户ID
     * @return 用户
     */
    public Member selectMemberById(Long id) {
        return memberMapper.getById(id);
    }

    /**
     * 查询用户列表
     *
     * @param member 用户
     * @return 用户
     */
    public List<Member> selectMemberList(Member member) {
        Query query = new Query();
        query.orderby("id", Sort.DESC);
        List<Member> list = memberMapper.list(query);
        return list;
    }

    /**
     * 新增用户
     *
     * @param member 用户
     * @return 结果
     */
    public int insertMember(Member member) {
        return memberMapper.saveIgnoreNull(member);
    }

    /**
     * 修改用户
     *
     * @param member 用户
     * @return 结果
     */
    public int updateMember(Member member) {
        return memberMapper.updateIgnoreNull(member);
    }

    /**
     * 删除用户信息
     *
     * @param id 用户ID
     * @return 结果
     */
    public int deleteMemberById(Long id) {
        return memberMapper.deleteById(id);
    }

    /**
     * 查询用户
     *
     * @param openid 用户ID
     * @return 用户
     */
    public Member selectMemberByOpenid(String openid) {
        return memberMapper.getByColumn("mini_openid",openid);
    }
}